﻿
using System;
using System.Data;
using System.Web.UI.WebControls;
using MyWeb.Business;
using MyWeb.Common;
using MyWeb.Data;
namespace MyWeb.Admins{public partial class GroupProduct : System.Web.UI.Page{static bool Insert = false;protected void Page_Load(object sender, EventArgs e){if (!IsPostBack){Session["folder"] = "GroupProduct"; BindGrid();}}
private void BindGrid(){grdGroupProduct.DataSource = GroupProductService.GroupProduct_GetByAll() ;grdGroupProduct.DataBind();}
protected void btnThem_Click(object sender, EventArgs e){pnShow.Visible = false;pnUpdate.Visible = true;ControlClass.ResetControlValues(this);Session["upload"] = null;Insert=true;}
protected void btnXoa_Click(object sender, EventArgs e)
{
    try
    {
        DataGridItem item = default(DataGridItem);
        for (int i = 0; i < grdGroupProduct.Items.Count; i++)
        {
            item = grdGroupProduct.Items[i];
            if (item.ItemType == ListItemType.AlternatingItem | item.ItemType == ListItemType.Item)
            {
                if (((CheckBox)item.FindControl("ChkSelect")).Checked)
                {
                    string strId = item.Cells[1].Text;
                    try
                    {
                        GroupProductService.GroupProduct_Delete(strId);
                    }
                    catch { }
                }
            }
        } grdGroupProduct.CurrentPageIndex = 0; BindGrid();
    }
    catch { }
}
    protected void grdGroupProduct_ItemCommand(object source, DataGridCommandEventArgs e){Data.GroupProductInfo strCA=new GroupProductInfo();
String Id = e.CommandArgument.ToString();
if  (e.CommandName=="Edit"){DataTable dt = GroupProductService.GroupProduct_GetById(Id);txtId.Text=dt.Rows[0]["Id"].ToString();txtName.Text=dt.Rows[0]["Name"].ToString();txtContent.Text=dt.Rows[0]["Content"].ToString();txtImages.Text=dt.Rows[0]["Images"].ToString();txtOrder.Text=dt.Rows[0]["Order"].ToString();txtStatus.Text=dt.Rows[0]["Status"].ToString();pnUpdate.Visible = true;pnShow.Visible = false;}else{GroupProductService.GroupProduct_Delete(Id);BindGrid();}}
 protected void lblBack_Click(object sender, EventArgs e){pnUpdate.Visible = false;pnShow.Visible = true;Insert=false;}protected void lblUpdate_Click(object sender, EventArgs e){string image = Session["upload"] == null ? "" : Session["upload"].ToString();
    #region[TestInput]
if (txtId.Text.Trim().Equals("")){WebMsgBox.Show("Id không thể trống !");txtId.Focus();return;}if (txtName.Text.Trim().Equals("")){WebMsgBox.Show("Name không thể trống !");txtName.Focus();return;}if (txtContent.Text.Trim().Equals("")){WebMsgBox.Show("Content không thể trống !");txtContent.Focus();return;}if (txtImages.Text.Trim().Equals("")){WebMsgBox.Show("Images không thể trống !");txtImages.Focus();return;}if (txtOrder.Text.Trim().Equals("")){WebMsgBox.Show("Order không thể trống !");txtOrder.Focus();return;}if (txtStatus.Text.Trim().Equals("")){WebMsgBox.Show("Status không thể trống !");txtStatus.Focus();return;}
#endregion
Data.GroupProductInfo obj=new Data.GroupProductInfo();obj.Id = txtId.Text;obj.Name = txtName.Text;obj.Content = txtContent.Text;obj.Images = txtImages.Text;obj.Order = txtOrder.Text;obj.Status = txtStatus.Text;if (Insert == true){GroupProductService.GroupProduct_Insert(obj);}else{GroupProductService.GroupProduct_Update(obj);}BindGrid();pnShow.Visible = true;pnUpdate.Visible = false;Insert = false;
}protected void grdGroupProduct_PageIndexChanged(object source, DataGridPageChangedEventArgs e){grdGroupProduct.CurrentPageIndex = e.NewPageIndex;BindGrid();} protected void grdGroupProduct_ItemDataBound(object sender, DataGridItemEventArgs e)
{
ListItemType itemType = e.Item.ItemType;if ((itemType != ListItemType.Footer) && (itemType != ListItemType.Separator)){if (itemType == ListItemType.Header){object checkBox = e.Item.FindControl("chkSelectAll");if ((checkBox != null)){((CheckBox)checkBox).Attributes.Add("onClick", "Javascript:chkSelectAll_OnClick(this)");
}
}else{
string tableRowId = grdGroupProduct.ClientID + "_row" + e.Item.ItemIndex.ToString();
e.Item.Attributes.Add("id", tableRowId);
object checkBox = e.Item.FindControl("chkSelect");
if ((checkBox != null))
{e.Item.Attributes.Add("onMouseMove", "Javascript:chkSelect_OnMouseMove(this)");
e.Item.Attributes.Add("onMouseOut", "Javascript:chkSelect_OnMouseOut(this," + e.Item.ItemIndex + ")");((CheckBox)checkBox).Attributes.Add("onClick", "Javascript:chkSelect_OnClick(this," + e.Item.ItemIndex + ")");}}}}
}
}